package cn.csxw.openchina.ui.adapter;

import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import cn.csxw.openchina.R;
import cn.csxw.openchina.base.BaseRecAdapter;
import cn.csxw.openchina.entity.bean.FriendBean;
import cn.csxw.openchina.utils.Global;

/**
 * 我的界面中  关注Adapter
 */

public class MyFollowAdapter extends BaseRecAdapter<FriendBean> {

    public MyFollowAdapter(ArrayList data) {
        super(data);
    }
    @Override
    protected void onItemClick(View v, int position) {

    }

    @Override
    protected BaseViewHolder getViewHolder(View itemView) {
        //创建Holder对象   这里在里面可以匿名内部类   但建议不用
        return new MyFollowHolder(itemView);
    }

    @Override
    protected View getItemView(ViewGroup parent) {
        return Global.inflate(R.layout.view_fragment_follow, parent);
    }

     class MyFollowHolder extends BaseViewHolder {
        @BindView(R.id.iv_follow_photo)
        ImageView mIvFollowPhoto;
        @BindView(R.id.tv_follow_name)
        TextView mTvFollowName;
        @BindView(R.id.tv_follow_address)
        TextView mTvFollowAddress;
        @BindView(R.id.tv_follow_des)
        TextView mTvFollowDes;

        public MyFollowHolder(View itemView) {
            super(itemView);
        }

        @Override//设置数据的展示
        public void setData(FriendBean friendBean, int Position) {
            mTvFollowName.setText(friendBean.name);
            int gender = friendBean.gender;
            Drawable drawable ;
            if(gender == 2){
              drawable = Global.getDrawable(R.drawable.userinfo_icon_female);
            }else{
                drawable = Global.getDrawable(R.drawable.userinfo_icon_male);
            }
            drawable.setBounds(0,0,drawable.getMinimumWidth(),drawable.getMinimumHeight());
            mTvFollowName.setCompoundDrawables(null,null, drawable,null);
            if(TextUtils.isEmpty(friendBean.from)){
                mTvFollowAddress.setVisibility(View.GONE);
            }else{
                mTvFollowAddress.setText(friendBean.from);
            }
            mTvFollowDes.setText(friendBean.expertise);
        }
    }

}
